package com.action;

import java.util.Arrays;
import java.util.List;

import com.base.action.BaseAction;
import com.model.Role;
import com.opensymphony.xwork2.ModelDriven;
import com.service.IRoleService;

public class RoleAction extends BaseAction implements ModelDriven<Role> {
	private static final long serialVersionUID = 1L;

	
	private IRoleService roleService;
	private Role role;
	
	public void setRoleService(IRoleService roleService) {
		this.roleService = roleService;
	}
	
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Override
	public Role getModel() {
		return role;
	}
	
	public String getAll(){
		List<Role> list=roleService.getAll();
		this.getRequest().setAttribute("modelList", list);
		return "getAll";
	}
	public String add(){
		roleService.add(role);
		return "add";
	}
	public String del(){
		Integer id=Integer.parseInt(this.getRequest().getParameter("id"));		
		roleService.delete(id);
		return "del";
	}
	public String get(){
		Integer id=Integer.parseInt(this.getRequest().getParameter("id"));		
		Role model=roleService.get(id);
		this.getRequest().setAttribute("model", model);
		return "get";
	}
	public String edit(){
		System.out.println(role.getId()+"-------"+role.getRolename());
		roleService.update(role);
		return "edit";
	}
	public String multiDel(){
		String[] arr=this.getRequest().getParameterValues("select");
		System.out.println(Arrays.asList(arr));
		for(int i=0;i<arr.length;i++){
			int id=Integer.parseInt(arr[i]);
			roleService.delete(id);
		}
		return "multiDel";
	}
}
